home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / PLOTCICN / DRAW_CIC.C
C/C++ Source or Header  |  1990-03-05  |  4KB  |  149 lines

  1. /***********************************************************************************/
  2. /*  Draw CICN.c                                                                    */
  3. /*  BY ALLEN PRESCOTT                                                              */
  4. /*  MARCH 1990                                                                     */
  5. /***********************************************************************************/
  6. /*
  7.   INCLUDE FILES
  8. */
  9. #include    "HyperXCMD.h"
  10. #include    <SetUpA4.h>
  11. #include    <Color.h>
  12. /*
  13.   FUNCTION PROTOTYPES
  14. */
  15. pascal void main(XCmdBlockPtr paramPtr);
  16. int candocolor();
  17. /*
  18.   MAIN CODE SEGMENT
  19. */
  20. pascal void main(XCmdBlockPtr paramPtr)
  21. {
  22. /*
  23.   LOCAL VARIABLES
  24. */
  25.     Str255 paramvalue;        /* STRING FOR RECEIVING PARAMETERS  */
  26.     Point myPt;                /* POINT FOR TOPLEFT COORDINATE     */
  27.     long top,left,tid;        /* LONGS TO CONVERT COORDINATE INTO */
  28.     int theID;                /* ID OF CICN RESOURCE              */
  29.     CIconHandle theCICN;    /* HANDLE FOR CICN RESOURCE         */
  30.     CGrafPort myCPort;        /* COLOR GRAFPORT TO DRAW INTO      */
  31.     GrafPort oldPort;        /* OLD PORT TO SAVE                 */
  32.     ResType theType;        /* TYPE OF RESOURCE FOR GETRESINFO  */
  33.     Rect theRect;            /* RECT TO PLOT CICN INTO           */
  34. /*
  35.   SET UP THE GLOBALS.  EVEN THOUGH WE DO NOT USE ANY I ALWAYS DO THIS JUST IN CASE
  36. */
  37.     RememberA0();
  38.     SetUpA4();
  39. /*
  40.   START OF CODE
  41. */
  42. /*
  43.   MAKE SURE THAT COLOR QUICKDRAW IS AVAILABLE
  44. */
  45.     if (!candocolor())
  46.     {
  47.         SendCardMessage(paramPtr,(StringPtr)"\pput \"-- Plot CICN ERROR, color not available\"");
  48.         SysBeep(1);
  49.         return;
  50.     }
  51. /*
  52.   WE MUST HAVE AT LEAST THREE PARAMETERS
  53. */
  54.     if ( paramPtr->paramCount < 3 )
  55.     {
  56.         SendCardMessage(paramPtr,(StringPtr)"\pput \"-- Plot CICN ERROR, wrong number of parameters\"");
  57.         SysBeep(1);
  58.         return;
  59.     }
  60. /* PARAMETER 1(INDEX 0) IS THE LEFT EDGE OF THE CICN IN LOCAL COORDINATES */    
  61.     ZeroToPas(paramPtr,(unsigned char *)*(paramPtr->params[0]),(StringPtr)¶mvalue);
  62.     StringToNum(paramvalue,&left);
  63. /* PARAMETER 2(INDEX 1) IS THE TOP OF THE CICN IN LOCAL COORDINATES */
  64.     ZeroToPas(paramPtr,(unsigned char *)*(paramPtr->params[1]),(StringPtr)¶mvalue);
  65.     StringToNum(paramvalue,&top);
  66. /* IF PARAMETER 3 IS NOT THE EMPTY STRING THEN WE USE IT TO LOCATE THE CICN */
  67.     if (**paramPtr->params[2] != 0)
  68.     {
  69.         ZeroToPas(paramPtr,(unsigned char *)*(paramPtr->params[2]),(StringPtr)¶mvalue);
  70.         SetResLoad(FALSE);
  71.         theCICN = (CIconHandle)GetNamedResource('cicn',paramvalue);
  72.         SetResLoad(TRUE);
  73.         if (theCICN == 0L)
  74.         {
  75.             SendCardMessage(paramPtr,(StringPtr)"\pput \"-- Plot CICN ERROR, cannot get color icon resource\"");
  76.             SysBeep(1);
  77.             return;
  78.         }
  79.         GetResInfo(theCICN,&theID,theType,paramvalue);
  80.         ReleaseResource(theCICN);
  81.     }
  82. /* IF PARAMETER 3 IS THE EMPTY STRING THEN WE USE PARAMETER 4 AS THE ID OF THE CICN */
  83.     else
  84.     {
  85.         if ( paramPtr->paramCount < 4 )
  86.         {
  87.             SendCardMessage(paramPtr,(StringPtr)"\pput \"-- Plot CICN ERROR, invalid color icon resource name\"");
  88.             SysBeep(1);
  89.             return;
  90.         }
  91.         ZeroToPas(paramPtr,(unsigned char *)*(paramPtr->params[3]),(StringPtr)¶mvalue);
  92.         StringToNum(paramvalue,&tid);
  93.         theID = tid;
  94.     }    
  95. /* GET THE CICN RESOURCE */
  96.     theCICN = GetCIcon(theID);
  97.     if (theCICN == 0L)
  98.     {
  99.         SendCardMessage(paramPtr,(StringPtr)"\pput \"-- Plot CICN ERROR, cannot get color icon resource\"");
  100.         SysBeep(1);
  101.         return;
  102.     }
  103. /*
  104.   CONVERT THE COORDINATES TO GLOBAL SO WE CAN KEEP THEM IN OUR NEW COORDINATE SYSTEM
  105. */
  106.     SetPt(&myPt,left,top);
  107.     LocalToGlobal(&myPt);
  108. /*
  109.   OPEN A COLOR PORT TO DRAW THE COLOR ICON INTO
  110. */
  111.     GetPort(&oldPort);
  112.     OpenCPort(&myCPort);
  113.     SetPort(&myCPort);
  114. /*
  115.   CONVERT THE COORDINATES BACK TO LOCAL AND WE ARE READY TO PLOT
  116. */
  117.     GlobalToLocal(&myPt);
  118.     SetRect(&theRect,myPt.h,myPt.v,myPt.h+32,myPt.v+32);
  119.     PlotCIcon(&theRect,theCICN);
  120. /*
  121.   CLEAN UP AND WE ARE DONE
  122. */
  123.     DisposCIcon(theCICN);
  124.     CloseCPort(&myCPort);
  125.     SetPort(&oldPort);
  126. /*
  127.   RESTORE THE REGISTERS BEFORE RETURNING
  128. */
  129.     RestoreA4();
  130. }
  131. /*****************************************************************************/
  132. /*
  133.  FUNCTION TO DETERMINE IF COLOR QUICKDRAW IS PRESENT AND THE MODE IS AT
  134.  LEAST 16 COLORS
  135. */
  136. int candocolor()
  137. {
  138.     SysEnvRec theworld;
  139.     OSErr err;
  140.  
  141.     err = SysEnvirons(2, &theworld);
  142.     if (err != noErr)
  143.         return(FALSE);
  144.     if (theworld.hasColorQD != TRUE)
  145.         return(FALSE);
  146.     else
  147.         return(TRUE);
  148. }
  149.